#include <openssl/ec.h>
#include <openssl/evp.h>
#include <iostream>
#include <openssl/ossl_typ.h>
using namespace std;
EVP_PKEY* EccKey()
{
    auto key = EC_KEY_new();

    //多种椭圆曲线
    int nums = EC_get_builtin_curves(NULL, 0);

    EC_builtin_curve curvs[nums];
    EC_get_builtin_curves(curvs, nums);
    for (int i = 0; i < nums; ++i) {
        cout<<curvs[i].nid<<":"<<curvs[i].comment<<endl;
    }

    //选择椭圆曲线，设置参数 注意，有的算法不能加解密
    auto group = EC_GROUP_new_by_curve_name(NID_sm2);
    if(!group){
        cout<<"Err1"<<endl;
        return nullptr;
    }
    
    auto pkey = EC_KEY_new();
    EC_KEY_set_group(pkey, group);   
    int re = EC_KEY_generate_key(pkey);
    if(re != 1){
        return nullptr;
    }
    re = EC_KEY_check_key(pkey);
    if(re != 1){
        return nullptr;
    }
    EVP_PKEY* ppkey = EVP_PKEY_new();
    EVP_PKEY_set1_EC_KEY(ppkey, pkey);
    EC_KEY_free(pkey);
    return ppkey;
}

int a(EVP_PKEY* ppkey)
{
    auto ctx = EVP_PKEY_CTX_new(ppkey,nullptr);
    EVP_PKEY_encrypt_init(ctx);
    EVP_PKEY_encrypt(ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen);
    EVP_PKEY_decrypt_init(ctx);
    EVP_PKEY_decrypt(ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen);
}

//椭圆曲线签名与验签与EVP一致


int main()
{
    EccKey();
}
